package com.todod.common.util;

import javax.servlet.http.HttpServletRequest;

/**
 * @author gsh
 * @version 创建时间：2017-11-27 下午3:12:09
 * 
 */
public class IpAddr {

	// 淘宝API
	private static String urlStr = "http://ip.taobao.com/service/getIpInfo.php";

	/**
	 * 获取IP地址
	 * 
	 * @param request
	 * @return
	 */
	public static String getIpAddr(HttpServletRequest request) {
		String ip = request.getHeader("x-forwarded-for");
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("WL-Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getRemoteAddr();
		}
		return ip;
	}

	public static void main(String[] args) {

	}
}
